package com.fsc.mapper;

import com.fsc.entity.domain.StudentInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fsc.entity.domain.TeacherInfo;
import com.fsc.entity.dto.StudentDTO;
import com.fsc.entity.dto.TeacherDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
* @author 86183
* @description 针对表【student_info(学生信息表)】的数据库操作Mapper
* @createDate 2024-06-02 13:15:22
* @Entity com.fsc.domain.StudentInfo
*/
@Mapper
public interface StudentInfoMapper extends BaseMapper<StudentInfo> {

    @Select("SELECT * FROM student_info WHERE student_id IN (SELECT student_id FROM stu_part_teach WHERE teacher_id = #{teacherId})")
    List<StudentInfo> getStudentsByTeacherId(@Param("teacherId") int teacherId);

    @Select("SELECT * FROM student_info WHERE student_id IN (SELECT student_id FROM stu_part_teach WHERE parent_id = #{parentId})")
    List<StudentInfo> getStudentsByParentId(@Param("parentId") int parentId);

    @Select("SELECT * FROM student_info")
    List<StudentInfo> getAllStudents();

    @Select("SELECT * FROM student_info WHERE student_id= #{studentId}")
    StudentInfo getStudentById(int studentId);

    @Update("UPDATE student_info " +
            "SET " +
            "gender = #{gender}, " +
            "student_name = #{studentName} " +
            "WHERE student_id= #{studentId}")
    void update(StudentDTO studentDTO);

    @Select("SELECT student_name FROM student_info WHERE student_id = #{studentId}") // 新增查询
    String getStudentNameById(@Param("studentId") int studentId);
}




